#include "soc.h"
#include "stdlix.h"


int receive_from_server(/*ServerMessage* mes*/)
{
//    int /*listensock,*/i = 0;
//    char recvbuff[1024];
	static const int opt=1;
    struct sockaddr_in6 serveraddr;
//    FILE * server = NULL;
	bzero(&serveraddr,sizeof(serveraddr));
    //    bzero(recvbuff,1024);
        serveraddr.sin6_family=AF_INET6;
        serveraddr.sin6_addr=in6addr_any;
//        inet_pton(AF_INET6,"2001:da8:bf:15:a90:90ff:fe90:9090",&serveraddr.sin6_addr);//IPV6 addr

        serveraddr.sin6_port=htons(SERVER_PORT);
//    printf("receive_from_server\n");
    if(!listensock)
    {

    	listensock=socket(AF_INET6,SOCK_STREAM,0);
    	if(listensock < 0)
    	{
//    		perror("create socket error");
    		close(listensock);
    		listensock = FALSE;
    		return -1;
    	}
    	setsockopt(listensock,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt));
        if(bind(listensock,(struct sockaddr*)&serveraddr,sizeof(struct sockaddr_in6)))
        {
//        	perror("bind error");
    		close(listensock);
    		listensock = FALSE;
        	return -1;
        }
        if(listen(listensock,1024))
        {
//        	perror("listen error");
    		close(listensock);
    		listensock = FALSE;
        	return -1;
        }
    }

/*    while(1)
    {*/
//    printf("listen sock=%d,port=%d\n",listensock,SERVER_PORT);
    return accept(listensock,(struct sockaddr*)NULL,NULL);
//    printf("recving\n");
//    /*len=*/recv(connsock,recvbuff,1024/*sizeof(msg)*/,0);
//    printf("recved\n");
/*    for(i = 0;i<1024;i++)
    	putchar(recvbuff[i]);*/
//    printf("recv buff  %100s\n",recvbuff);
//    return NULL;
    //    if(remoteAddr.sin6_addr == )
//    	printf("asdf\n");
/*		if (pthread_create(&id,NULL,(void *)dealServerMessage, &connsock))
				printf("main dealServerMessage thread error!\n");*/
//    }

//    mes=(ServerMessage*)recvbuff;
    //printf("%s\n",recvbuff);
    //fflush(stdout);
    //sleep(2);
//    close(connsock);
//    close(listensock);
//    return 1;
   
}
